package com.yanq.liancar.adapter;
/*
 *  @创建者     liyan
 *  @创建时间   2018/9/13  10:40
 *  @描述       ${TODO}
 */
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanq.liancar.R;
import com.yanq.liancar.bean.SelectClassifyBean;

import java.util.List;

public class BigSelectClassifyAdapter  extends RecyclerView.Adapter<BigSelectClassifyAdapter.MyViewHolder> {
    private Context mContext;
    private List<SelectClassifyBean.DataBean> mList;
    private LayoutInflater mInflater;

    public BigSelectClassifyAdapter(Context context,List<SelectClassifyBean.DataBean> dataBeanList){
        this.mContext=context;
        this.mList=dataBeanList;
        mInflater=LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        view=LayoutInflater.from(mContext).inflate(R.layout.big_selectcalss,null,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        //holder.mImageView.setImageResource();
        holder.mTitle.setText(mList.get(position).getBig_classifyname());
        if(holder.mRecyclerView.getAdapter()==null) {
            holder.mRecyclerView.setAdapter(new SmallSelectClassAdapter(mContext, mList.get(position).getB2SmallClassifies(),mList.get(position).getBigclassifyid()));
        }/*else { holder.mRecyclerView.getAdapter().notifyDataSetChanged(); }*/

    }

    @Override
    public int getItemCount() {
        return  (mList == null ? 0 : mList.size());

    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        private RecyclerView mRecyclerView;
        private TextView mTitle;
        private ImageView mImageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            mRecyclerView=itemView.findViewById(R.id.recyclerview);
            //RecyclerView.LayoutManager manager = new LinearLayoutManager(mContext,LinearLayoutManager.HORIZONTAL,false);
//            LinearLayoutManager layoutManager = new GridLayoutManager(mContext,3) {
//                @Override
//                public RecyclerView.LayoutParams generateDefaultLayoutParams() {
//                    return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
//                            ViewGroup.LayoutParams.WRAP_CONTENT);
//                }
//            };
            //layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            RecyclerView.LayoutManager manager = new GridLayoutManager(itemView.getContext(),3);
            manager.setAutoMeasureEnabled(true);
            mRecyclerView.setNestedScrollingEnabled(false);
            mRecyclerView.setLayoutManager(manager);

            mTitle=itemView.findViewById(R.id.tv_title);
            mImageView =itemView.findViewById(R.id.img_title);
        }
    }

    public void setData(List<SelectClassifyBean.DataBean> mList){
        this.mList=mList;
        notifyDataSetChanged();
    }


}
